## Pylons DB Admin
## Copyright (C) 2004-2009  Ken Kinder
##
## This program is free software: you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation, either version 3 of the License, or
## (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program.  If not, see <http://www.gnu.org/licenses/>.
<%inherit file="base.mako"/>
<%def name="local_header()">
</%def>

<%def name="title()">
    ${c.instance} Data Browser
</%def>

<div class="ui-corner-top ui-widget-header page-nav">
    <h1><a href="${h.url_for(controller='dbadmin', action='index')}">Pylons DB Admin</a> / <a href="${h.url_for(controller='dbadmin', action='browse', instance=c.instance)}">${c.instance}</a> / Data Browser / ${c.table}</h1>
</div>

% if c.dbtable.primary_key.columns.keys():
    
    <table id="browser"></table>
    <div id="bnav"></div>
    <div id="column-chooser"></div> 
    <div id="pager"></div>
    
    <script type="text/javascript">
        title = ${h.json_dumps('%s - %s' % (c.instance, c.table))|n};
        
        colModel = ${h.json_dumps(c.colModel)|n};
        colNames = ${h.json_dumps(c.colNames)|n};
        
        $('#browser').jqGrid({
            url: "${h.url_for(controller='dbadmin', action='data', instance=c.instance)}",
            pager: $('#bnav'),
            datatype: 'json',
            caption: ${c.table|h.json_dumps},
            rowNum: 30,
            rowList: (10,20,30,50,100),
            height: 'auto',
            width: 'auto',
            autowidth: true,
            viewrecords: true,
            hidegrid: false,
            colNames: colNames,
            colModel: colModel
        });
        $('#browser').jqGrid('navGrid', '#bnav', {
            edit:false,
            add:false,
            del:false,
            search:false,
            
            refreshtitle: 'Refresh Data',
            refreshstate: 'current'
        }); 
        
    </script>
% else:
    <p>Data browsing is not supported on tables without primary keys.</p>
% endif
